package com.hongxun.modules.api.controller;

import java.util.List;
import java.util.Map;

import com.hongxun.common.annotation.SysLog;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.hongxun.modules.api.entity.BDataDictionaryEntity;
import com.hongxun.modules.api.service.BDataDictionaryService;
import com.hongxun.common.utils.PageUtils;
import com.hongxun.common.utils.Query;
import com.hongxun.common.utils.R;




/**
 * 数据字典
 * 
 * @author zkcn
 * @email youeremail@163.com
 * @date 2018-07-23 15:49:42
 */
@RestController
@RequestMapping("/api/bdatadictionary")
public class BDataDictionaryController {
	@Autowired
	private BDataDictionaryService bDataDictionaryService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("api:bdatadictionary:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
        String wheres ="1=1";
        if(query.get("d_code")!=null&&!query.get("d_code").toString().equals(""))
		{
			wheres+=" and  d_code = '" + query.get("d_code").toString()+"' ";
		}
        query.put("filterSql",wheres);
		List<BDataDictionaryEntity> bDataDictionaryList = bDataDictionaryService.queryList(query);
		int total = bDataDictionaryService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(bDataDictionaryList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	@RequestMapping("/select")
	public R select(@RequestParam Map<String, Object> params){
		//查询列表数据
		Query query = new Query(params);
		String wheres ="1=1";
		if(query.get("d_code")!=null&&!query.get("d_code").toString().equals(""))
		{
			wheres+=" and  d_code = '" + query.get("d_code").toString()+"' ";
		}
		query.put("filterSql",wheres);
		List<BDataDictionaryEntity> bDataDictionaryList = bDataDictionaryService.queryList(query);

		return R.ok().put("returnlist", bDataDictionaryList);
	}
	@RequestMapping("/selectlike")
	public R selectlike(@RequestParam Map<String, Object> params){
		//查询列表数据
		Query query = new Query(params);
		String wheres ="1=1";
		if(query.get("d_code")!=null&&!query.get("d_code").toString().equals(""))
		{
			wheres+=" and  d_code like '%" + query.get("d_code").toString()+"%' ";
		}
		query.put("filterSql",wheres);
		List<BDataDictionaryEntity> bDataDictionaryList = bDataDictionaryService.queryList(query);

		return R.ok().put("returnlist", bDataDictionaryList);
	}


	/**
	 * 信息
	 */
	@RequestMapping("/info/{guid}")
	@RequiresPermissions("api:bdatadictionary:info")
	public R info(@PathVariable("guid") String guid){
		BDataDictionaryEntity bDataDictionary = bDataDictionaryService.queryObject(guid);
		
		return R.ok().put("bDataDictionary", bDataDictionary);
	}
	
	/**
	 * 保存
	 */
	@SysLog("添加数据字典")
	@RequestMapping("/save")
	@RequiresPermissions("api:bdatadictionary:save")
	public R save(@RequestBody BDataDictionaryEntity bDataDictionary){
		bDataDictionaryService.save(bDataDictionary);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@SysLog("修改数据字典")
	@RequestMapping("/update")
	@RequiresPermissions("api:bdatadictionary:update")
	public R update(@RequestBody BDataDictionaryEntity bDataDictionary){
		bDataDictionaryService.update(bDataDictionary);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@SysLog("删除数据字典")
	@RequestMapping("/delete")
	@RequiresPermissions("api:bdatadictionary:delete")
	public R delete(@RequestBody String[] guids){
		bDataDictionaryService.deleteBatch(guids);
		
		return R.ok();
	}
	
}
